// __PUBLIC__/js/page/admin/user/addnode
require(['../../common'], function() {
  require(['user.addnode'])
})

define('user.addnode', [
  'jquery'
], function($) {
  'use strict';

  function add() {
    var name = $('#name').val()
    var title = $('#title').val()
    var status = $('input[name="status"]:checked').val()
    var vpid = $('#vpid').val()

    if (name === '') {
      $('#vaname').html('*'+lang.nodeName+lang.notNull).css('color', 'red')
      return
    }

    if (title === '') {
      $('#vtitle').html('*'+lang.nodeStatus+lang.notNull).css('color', 'red')
      return
    }

    $.post(APP + '?app=admin&m=User&a=addNodeManage', {
      name: name,
      title: title,
      status: status,
      pid: vpid
    }).done(function(res) {
      if (res == '2') {
        setInterval(function() {
          window.location.href = APP + '?app=admin&m=User&a=nodeManage'
        }, 300)
      } else if (res == '0') {
        $('#vaname').html(lang.addFails).css('color', 'red')
      }
    })
  }

})
